exports.MMBottomBar = GL2.Node.subclass(
{
    classname: 'MMBottomBar',
    
    initialize: function() 
    {
		this._backgroundImage = null;
		this._menuButton = null;
		this._homeButton = null;
    },
	
	createView: function()
	{
		var positionY = STARTING_Y;
		
		var backgroundPath = this.getBaseResourcePath() + "bar-background.png";
		
		this._backgroundImage = GLFactory.getSprite([TCUtil.getAdjustedX(0),TCUtil.getAdjustedY(positionY)], null, backgroundPath, [TCUtil.getScreenWidth(),TCUtil.getAdjustedHeight(BACKGROUND_HEIGHT)]);
		this.addChild(this._backgroundImage);
		
		this.makeTouchSwallower();//DONT CHANGE ITS POSITIOIN
		
		if(DatabaseInterface._isVisitingNeighbor)
		{
			var exitButtonImagePathNormal = this.getBaseResourcePath() + "generic-button-normal.png";
			var exitButtonImagePathPressed = this.getBaseResourcePath() + "generic-button-pressed.png";
			
			var giftButtonImagePathNormal = this.getBaseResourcePath() + "gift-button-normal.png";
			var giftButtonImagePathPressed = this.getBaseResourcePath() + "gift-button-pressed.png";
		
			var stealButtonNormal = this.getBaseResourcePath() + "steal-button-normal.png";
			var stealButtonPressed = this.getBaseResourcePath() + "steal-button-pressed.png";
		
			this._homeButton = new GLButton(exitButtonImagePathNormal, exitButtonImagePathPressed, TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(50), this.onHomeTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("EXIT"), new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(120));
			this._homeButton.setPosition(TCUtil.getAdjustedX(260),TCUtil.getAdjustedY(30));
			this._homeButton.setDisabledImagePath(exitButtonImagePathPressed);	
			
			this._giftButton = new GLButton(giftButtonImagePathNormal, giftButtonImagePathPressed, TCUtil.getAdjustedX(40),TCUtil.getAdjustedY(40), this.onGiftTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("GIFTS"), new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
			this._giftButton.setPosition(TCUtil.getAdjustedX(150),TCUtil.getAdjustedY(20));
			this._giftButton.setDisabledImagePath(giftButtonImagePathPressed);	
			this._giftButton.setButtonTextBelowButton();
			
			this._stealButton = new GLButton(stealButtonNormal, stealButtonPressed, TCUtil.getAdjustedX(40),TCUtil.getAdjustedY(40), this.onStealTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("STEAL"), new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
			this._stealButton.setPosition(TCUtil.getAdjustedX(50),TCUtil.getAdjustedY(20));
			this._stealButton.setDisabledImagePath(stealButtonPressed);
			this._stealButton.setButtonTextBelowButton();
		}
		else
		{
			var menuButtonImagePathNormal = this.getBaseResourcePath() + "generic-button-normal.png";
			var menuButtonImagePathPressed = this.getBaseResourcePath() + "generic-button-pressed.png";
		
			this._menuButton = new GLButton(menuButtonImagePathNormal, menuButtonImagePathPressed, TCUtil.getAdjustedX(100),TCUtil.getAdjustedY(50), this.onMenuTouch.bind(this), this._backgroundImage, 3, Core.Localization.getString("MENU"), new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(120));
			this._menuButton.setPosition(TCUtil.getAdjustedX(260),TCUtil.getAdjustedY(30));
			this._menuButton.setDisabledImagePath(menuButtonImagePathPressed);
		}
	},
	
	onHomeTouch: function()
	{
		if(!TutorialManager.getHasCompletedTutorial())
		{
			this.hideTutorialIndicatorForMenu();
			DatabaseInterface._isVisitingNeighbor = false;
			TutorialManager.showNextTutorialStep();
		}
		else
		{
			DatabaseInterface._isVisitingNeighbor = false;
			MMFriendActionManager.postFriendActionsDone();
			GameCentralHandler.addTransitionScreen();
			DatabaseInterface.loadUser();
			DatabaseHelper.unloadUser();
		}
	},
	
	onGiftTouch: function()
	{
		this.hideLeftTutorialIndicatorForMenu();
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		var giftMenu = new GiftMainView();
		giftMenu.createView();
		NGWindow.document.addChild(giftMenu);
	},
	
	onStealTouch: function()
	{
		this.hideLeftTutorialIndicatorForMenu();
		TutorialManager.hideTutorialPopup();
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		var message = Core.Localization.getString("CONFORMATION_FOR_STEALING");
		var alert = new GAGLAlertWindow(Core.Localization.getString("MESSAGE"),message,this);
		if(TutorialManager.getHasCompletedTutorial())
		{
			alert.setType("okwithcancel");	
		}
		alert.setTagValue("100");
		alert.show();
	},
	
	clickedButtonAtIndex: function(buttonIndex,alerWindow)
	{
		if (buttonIndex == 0) 
		{
			if(alerWindow.getTagValue() == "100")
			{
				MMFriendActionManager.stealFriendsCustomers();
				if(!TutorialManager.getHasCompletedTutorial())
				{
					this.showTutorialForGifting();
				}
			}	
		} 
		else if (buttonIndex == 1)
		{
			
		}
		
	},
	
	onMenuTouch: function() 
	{	
		MMSoundManager.playEffect(BUTTON_TAP_SOUND);
		if(TutorialManager.getHasCompletedTutorial())
		{
			if(this._mainMenu)
			{
				this._mainMenu.destroy();
				this._mainMenu = null;
			}
			else
			{
				this._mainMenu = new MMMainMenu();
				this._mainMenu.createView();
				this._mainMenu.setDepth(3);
				MMGameLayer.getControlLayer().addChild(this._mainMenu);
			}
		}
		else
		{
			if(!this._mainMenu)
			{
				this._mainMenu = new MMMainMenu();
				this._mainMenu.createView();
				this._mainMenu.setDepth(3);
				MMGameLayer.getControlLayer().addChild(this._mainMenu);
				
				if(TutorialManager.getCurrentTutorialStep() == 6)
				{
					if(this._tutorialIndicatorForMenu)
					{
						this._tutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(120), TCUtil.getAdjustedY(200)]);
					}
		
					this._mainMenu.setButtonsEnable(false);
					
					var floorButton = this._mainMenu.getMenuButtonsArray().objectAtIndex(kMenuButton.kMenuButtonFloors);
					if(floorButton)
					{
						floorButton.setIsEnabled(true);
					}
				}
				
				else if(TutorialManager.getCurrentTutorialStep() == 7)
				{
					if(this._tutorialIndicatorForMenu)
					{
						this._tutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(120), TCUtil.getAdjustedY(115)]);
					}
		
					this._mainMenu.setButtonsEnable(false);
					
					var elevatorButton = this._mainMenu.getMenuButtonsArray().objectAtIndex(kMenuButton.kMenuButtonLifts);
					if(elevatorButton)
					{
						elevatorButton.setIsEnabled(true);
					}
				}
				
				else if(TutorialManager.getCurrentTutorialStep() == 10)
				{
					if(this._tutorialIndicatorForMenu)
					{
						this._tutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(50), TCUtil.getAdjustedY(115)]);
					}
		
					this._mainMenu.setButtonsEnable(false);
					
					var storeButton = this._mainMenu.getMenuButtonsArray().objectAtIndex(kMenuButton.kMenuButtonShops);
					if(storeButton)
					{
						storeButton.setIsEnabled(true);
					}
				}
				else if(TutorialManager.getCurrentTutorialStep() == 12)
				{
					if(!DatabaseInterface._isVisitingNeighbor)
					{
						if(this._tutorialIndicatorForMenu)
						{
							this._tutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(50), TCUtil.getAdjustedY(200)]);
						}
			
						this._mainMenu.setButtonsEnable(false);
						
						var zoomButton = this._mainMenu.getMenuButtonsArray().objectAtIndex(kMenuButton.kMenuButtonZoom);
						if(zoomButton)
						{
							zoomButton.setIsEnabled(true);
						}
					}
					else
					{
						if(this._tutorialIndicatorForMenu)
						{
							this._tutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(50), TCUtil.getAdjustedY(400)]);
						}
					}
				}
			}
		}
	},
	
	showTutorialIndicatorForMenu: function(step)
	{
		this._tutorialIndicatorForMenu = new SwingAnimation(kSwingDirection.kSwingDirectionRight);
		this._tutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(125), TCUtil.getAdjustedY(440)]);
		this._tutorialIndicatorForMenu.createView();
		NGWindow.document.addChild(this._tutorialIndicatorForMenu);
		TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(120),TCUtil.getAdjustedY(230)]);
		
		if(TutorialManager.getCurrentTutorialStep() == 6)
		{
			TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_6"));
		}
		else if(TutorialManager.getCurrentTutorialStep() == 7)
		{
			TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_7"));	
		}
		else if(TutorialManager.getCurrentTutorialStep() == 10)
		{
			TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_10"));	
		}		
		else if(TutorialManager.getCurrentTutorialStep() == 12)
		{
			//TutorialManager.hideTutorialPopup();//getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_0"));
			//TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(120),TCUtil.getAdjustedY(45)]);
			if(step == "step_12_H")
			{
				TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_12_H"));
			}
			else
			{
				TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_12_A"));
			}	
		}	
	},
	
	disableSocialButtons: function()
	{
		if(this._homeButton)
		{
			this._homeButton.setIsEnabled(false);
		}
		if(this._giftButton)
		{
			this._giftButton.setIsEnabled(false);
		}
		if(this._stealButton)
		{
			this._stealButton.setIsEnabled(false);
		}
	},
	
	showTutorialForSocialActions: function()
	{
		this.disableSocialButtons();
		this.showTutorialForFriendCoin();
	},
	
	showTutorialForStealing: function()
	{		
		TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(70),TCUtil.getAdjustedY(220)]);
		TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_12_F"));
		this.showLeftTutorialIndicatorForMenu();
		this._leftTutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(90), TCUtil.getAdjustedY(440)]);
		this._stealButton.setIsEnabled(true);
	},
	
	showTutorialForGifting: function()
	{
		TutorialManager.unhideTutorialPopup();
		TutorialManager.getTutorialPopup().setCurrentPosition([TCUtil.getAdjustedX(110),TCUtil.getAdjustedY(220)]);
		TutorialManager.getTutorialPopup().updateText(Core.Localization.getString("TUTORIAL_TEXT_12_G"));
		this.disableSocialButtons();
		this.showLeftTutorialIndicatorForMenu();
		this._leftTutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(190), TCUtil.getAdjustedY(440)]);
		this._giftButton.setIsEnabled(true);
	},
	
	showTutorialForHome: function()
	{
		this.disableSocialButtons();
		var step = "step_12_H"
		this.showTutorialIndicatorForMenu(step);		
		this._homeButton.setIsEnabled(true);
	},
	
	showTutorialForFriendCoin: function()
	{
		this.disableSocialButtons();
		var storeContainer = MMGameLayer.getMallUI().getStoresUIArray().objectAtIndex(0);
		storeContainer.showTutorialForFriendCoin();
	},
	
	showTutorialForFriendTrash: function()
	{
		//this.disableSocialButtons();
		var noOfTrashes = TrashHandler.getTrashUIArray().getLength();
		if(noOfTrashes > 0)
		{
			TrashHandler.showTutorialForFriendTrash();
		}
		else
		{
			this.showTutorialForStealing();
		}
		//this.showTutorialForStealing();
	},
	
	showLeftTutorialIndicatorForMenu: function()
	{
		this._leftTutorialIndicatorForMenu = new SwingAnimation(kSwingDirection.kSwingDirectionLeft);
		this._leftTutorialIndicatorForMenu.setPosition([TCUtil.getAdjustedX(90), TCUtil.getAdjustedY(120)]);
		this._leftTutorialIndicatorForMenu.createView();
		NGWindow.document.addChild(this._leftTutorialIndicatorForMenu);
	},
	
	hideLeftTutorialIndicatorForMenu: function()
	{
		if(this._leftTutorialIndicatorForMenu)
		{
			this._leftTutorialIndicatorForMenu.destroy();
			this._leftTutorialIndicatorForMenu = null;
		}
	},
	
	hideTutorialIndicatorForMenu: function()
	{
		if(this._tutorialIndicatorForMenu)
		{
			this._tutorialIndicatorForMenu.destroy();
			this._tutorialIndicatorForMenu = null;
		}
	},
	
	disbaleMainMenuButton: function()
	{
		if(this._menuButton)
		{
			this._menuButton.setIsEnabled(false);
		}
	},
	
	enableMainMenuButton: function()
	{
		if(this._menuButton)
		{
			this._menuButton.setIsEnabled(true);
		}
	},
	
	getMainMenu: function()
	{
		if(this._mainMenu)
		{
			return this._mainMenu;
		}
		return null;
	},
	
	makeTouchSwallower: function()
	{
    	this._dissolveTouchesTarget = new GL2.TouchTarget();
    	this._dissolveTouchesTarget.setAnchor(0,0);
		this._dissolveTouchesTarget.setSize([TCUtil.getAdjustedX(480),TCUtil.getAdjustedY(BACKGROUND_HEIGHT)]);
        this._dissolveTouchesTarget.setPosition(TCUtil.getAdjustedY(0),TCUtil.getAdjustedX(0));
     
        this._myMessageListener = new Core.MessageListener();
		this._dissolveTouchesTarget.getTouchEmitter().addListener(this._myMessageListener, this.dissolveTouches.bind(this),10); //@ make this 10 go to Constants.
		this._backgroundImage.addChild(this._dissolveTouchesTarget);
	},
	
	dissolveTouches: function()
	{
		return true;
	},
	
	getNodeHeight: function()
	{
		return BACKGROUND_HEIGHT; 
	},

	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/";
	},
    
	destroy: function()
    {
    	if(this._giftButton)
    	{
    		this._giftButton.destroy();
    		this._giftButton = null;	
    	}
    	
    	if(this._homeButton)
    	{
    		this._homeButton.destroy();
    		this._homeButton = null;
    	}
		if(this._backgroundImage) 
		{
			this._backgroundImage.destroy();
			this._backgroundImage = null;
		}
		if(this._menuButton) 
		{
			this._menuButton.destroy();
			this._menuButton = null;
		}
		if(this._mainMenu)
		{
			this._mainMenu.destroy();
			this._mainMenu = null;
		}
		if(this._stealButton)
		{
			this._stealButton.destroy();
			this._stealButton = null;
		}
    },
});
